package com.ronglian.register_mini_program.util.WeiXin;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class HttpUtil {
    private static final int CONNECT_TIMEOUT = 5000;
    private static final String DEFAULT_ENCODING = "UTF-8";

    public HttpUtil() {
    }

    public static String postData(String urlStr, String data) {
        return postData(urlStr, data, (String) null);
    }

    public static String postData(String urlStr, String data, String contentType) {
        BufferedReader reader = null;

        try {
            URL url = new URL(urlStr);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            conn.setConnectTimeout(5000);
            conn.setReadTimeout(5000);
            if (contentType != null) {
                conn.setRequestProperty("content-type", contentType);
            }

            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            if (data == null) {
                data = "";
            }

            writer.write(data);
            writer.flush();
            writer.close();
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            StringBuilder sb = new StringBuilder();
            String line = null;

            while ((line = reader.readLine()) != null) {
                sb.append(line);
                sb.append("\r\n");
            }

            String var9 = sb.toString();
            return var9;
        } catch (IOException var19) {
            ;
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException var18) {
                ;
            }

        }

        return null;
    }
}
